package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// DailyCheckin holds the schema definition for the DailyCheckin entity.
type DailyCheckin struct {
	ent.Schema
}

// Fields of the DailyCheckin.
func (DailyCheckin) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("user_id").
			Comment("用户ID"),
		field.String("type").
			Comment("类型：早安/晚安"),
		field.String("mood").
			Optional().
			Comment("心情"),
		field.Text("note").
			Optional().
			Comment("备注"),
		field.Time("checkin_date").
			Default(time.Now).
			Comment("打卡日期"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the DailyCheckin.
func (DailyCheckin) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("user", User.Type).
			Ref("daily_checkins").
			Field("user_id").
			Unique().
			Required(),
	}
}
